package com.fort.teachermanagementsys.controller;


import com.fort.teachermanagementsys.entity.SysMenu;
import com.fort.teachermanagementsys.service.SysMenuService;
import com.fort.teachermanagementsys.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Allen
 * @since 2024-04-11
 */
@RestController
@RequestMapping("/sys-menu")
public class SysMenuController {


    @Autowired
    private SysMenuService sysMenuService;

    @GetMapping("/getAllMenu")
    public Result getAllMenu() {
        Result result = new Result();
        result.setCode(200);
        result.setMsg("success");
        result.setDetail(sysMenuService.menuList());
        return result;
    }

    // 更新菜单
    @PreAuthorize("hasPermission('system:menu:edit')")
    @PutMapping
    public void updateMenu(@RequestBody SysMenu menu) {
        sysMenuService.updateMenu(menu);
    }

    // 删除菜单
    @PreAuthorize("hasPermission('system:menu:delete')")
    @DeleteMapping("/{id}")
    public void deleteMenu(@PathVariable Integer id) {
        sysMenuService.deleteMenu(id);
    }

    // 获取单个菜单
    @PreAuthorize("hasPermission('system:menu')")
    @GetMapping("/{id}")
    public SysMenu getMenuById(@PathVariable Integer id) {
        return sysMenuService.getMenuById(id);
    }



}
